package com.hanbang.taitaigou.ui.activity.home;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hanbang.taitaigou.R;
import com.hanbang.taitaigou.ui.activity.base.BaseActivity;
import com.hanbang.taitaigou.ui.adapter.BaseRecylclerAdapter;
import com.hanbang.taitaigou.ui.adapter.BaseViewHolder;
import com.hanbang.taitaigou.ui.widget.autoloadding.OnLoaddingListener;
import com.hanbang.taitaigou.ui.widget.autoloadding.RecyclerViewAutoLoadding;
import com.hanbang.taitaigou.utils.other.ObjectUtils;
import com.hanbang.taitaigou.utils.ui.HorizontalDividerItemDecoration;
import com.hanbang.taitaigou.utils.ui.UiUtils;

import java.util.ArrayList;
import java.util.List;


public class TextActivity extends BaseActivity {
    RecyclerViewAutoLoadding recyclerViewAutoLoadding;
    MyAdapter adapter;
    List listDList = new ArrayList<String>();
//    WheelView wheelView;
//
//    LoopView picker_year;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aaa);
        initView();
        setOnClickListener();
    }

    /*
     * 设置点击事件
     */
    private void setOnClickListener() {

    }

    @SuppressWarnings("unused")
    private OnClickListener onClickListener = new OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {

                default:
                    break;
            }
        }
    };

    /*
     * 初始化view
     */
    int aaaa = 0;

    private void initView() {
        // 设置顶部的标题
        setBackArrows(findViewById(R.id.top_bar_left));
        setTop(null, R.mipmap.back, getString(R.string.botton_tab2), null, 0);

        for (int i = 0; i < 10; i++) {
            listDList.add("aaaaa" + i);
        }
        aaaa = 10;

        recyclerViewAutoLoadding = (RecyclerViewAutoLoadding) findViewById(R.id.listview);
        recyclerViewAutoLoadding.setItemAnimator(new DefaultItemAnimator());
        recyclerViewAutoLoadding.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).
                color(getResources().getColor(R.color.gray_ee)).
                size(ObjectUtils.dip2px(this, 1f)).build());
        recyclerViewAutoLoadding.setLayoutManager(new GridLayoutManager(this, 3));
        recyclerViewAutoLoadding.addHeaderView(UiUtils.getInflaterView(this, R.layout.home_list_item));

        recyclerViewAutoLoadding.addHeaderView(UiUtils.getInflaterView(this, R.layout.home_list_item));
        View view = UiUtils.getInflaterView(this, R.layout.home_list_item);
        ((TextView) view.findViewById(R.id.textview)).setText("ddddddddddddddd");
        recyclerViewAutoLoadding.addHeaderView(view);
        recyclerViewAutoLoadding.addFootView(UiUtils.getInflaterView(this, R.layout.home_list_item));
        recyclerViewAutoLoadding.setAdapter(adapter = new MyAdapter(this, listDList));


//        wheelView = (WheelView) findViewById(R.id.province);
//        wheelView.setData(listDList);
//
//        picker_year = (LoopView) findViewById(R.id.picker_year);
//
//        picker_year.setArrayList(listDList);

        recyclerViewAutoLoadding.setOnLoaddingListener(new OnLoaddingListener() {
            @Override
            public void onLoadding() {
                recyclerViewAutoLoadding.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        for (int i = 0; i < 10; i++) {
                            listDList.add("aaaaa" + i + aaaa);
                        }
                        aaaa += 10;
                        adapter.notifyDataSetChanged();
                        recyclerViewAutoLoadding.loaddingFinsh();
                    }
                }, 2000);
            }
        });

    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
    }

    private class MyAdapter extends BaseRecylclerAdapter<Object, BaseViewHolder> {

        public MyAdapter(Context context, List<Object> listDataS) {
            super(context, listDataS);
        }

        @Override
        public void onBindViewHolder(BaseViewHolder bholder, int position) {
            ViewHolder holder = (ViewHolder) bholder;
            holder.textView.setText(getItemData(position).toString());
        }

        @Override
        public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new ViewHolder(UiUtils.getInflaterView(context, R.layout.home_list_item));
        }

        class ViewHolder extends BaseViewHolder {
            TextView textView;

            public ViewHolder(View itemView) {
                super(itemView, onItemClickListener);
                textView = (TextView) itemView.findViewById(R.id.textview);
            }
        }
    }
}
